package com.example.demo01.Controller.webController;

import com.alibaba.fastjson.JSON;
import com.example.demo01.Service.webService.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class BookController {

    @Autowired
    BookService bookService;


//    @Autowired
//    TestMapper mapper;

    @RequestMapping("/books/GET")
    public String findAllBooks(){ return JSON.toJSONString(bookService.findAllBooks()); }

    /**
     * 从前端接受请求参数
     * */
    @GetMapping("/book")
    public String findBookByName(@RequestParam( value = "name", required = false, defaultValue = "0") String name){
        return JSON.toJSONString(bookService.findBookByName(name));
    }

//    @GetMapping("/book/{id}")
//    public String getBookById(@PathVariable("id") Integer id){
//        return JSON.toJSONString(mapper.getBookById(id));
//    }
//
//    @GetMapping("/books")
//    public String getBooks(){
//        return JSON.toJSONString(mapper.getBooks());
//    }
}
